#pragma once
template<typename T>
class Pressed
{
private:
    T pressed;
public:
    bool at(size_t x) const;
    bool at(size_t x, size_t y) const;
    void set(size_t x);
    void set(size_t x, size_t y);
    void unset(size_t x);
    void unset(size_t x, size_t y);
    size_t count();
    Pressed();
};
template<typename T>
bool Pressed<T>::at(size_t x) const
{
    return (this->pressed >> x) & 1;
}
template<typename T>
bool Pressed<T>::at(size_t x, size_t y) const
{
    return (this->pressed >> (x * 8 + y)) & 1;
}
template<typename T>
void Pressed<T>::set(size_t x)
{
    this->pressed = this->pressed | (static_cast<long long>(1) << x);
}
template<typename T>
void Pressed<T>::set(size_t x, size_t y)
{
    this->pressed = this->pressed | (static_cast<long long>(1) << (x * 8 + y));
}
template<typename T>
void Pressed<T>::unset(size_t x)
{
    this->pressed = this->pressed & (~(static_cast<long long>(1) << x));
}
template<typename T>
void Pressed<T>::unset(size_t x, size_t y)
{
    this->pressed = this->pressed & (~(static_cast<long long>(1) << (x * 8 + y)));
}

#define lowbit(a) (a)&(-(a))

template<typename T>
inline size_t Pressed<T>::count()
{
    T t = this->pressed;
    size_t ret = 0llu;
    while (t)
    {
        t -= t & (t ^ (t - 1));
        ret++;
    }
    return size_t(ret);
}

template<typename T>
Pressed<T>::Pressed()
{
    this->pressed = T();
}

typedef Pressed<_int64> Pressed64;
typedef Pressed<unsigned char> Pressed8;
